package jfconfig;

/**
 * Created : Apr 4, 2012
 *
 * @author pquiring
 */

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javax.swing.table.*;

public class VPNDialog extends javax.swing.JDialog {

  /**
   * Creates new form VPNDialog
   */
  public VPNDialog(java.awt.Frame parent, boolean modal, VPNPanel.VPN vpn) {
    super(parent, modal);
    initComponents();
    setPosition();
    if (vpn == null) return;
    //load vpn details
    name.setText(vpn.name);
    host.setText(vpn.host);
    username.setText(vpn.user);
    password.setText(vpn.pass);
    domain.setText(vpn.domain);
    domainsearch.setText(vpn.domainsearch);
    if (vpn.caps.equals("windows")) {
      customScroll.setVisible(false);
    } else {
      capsCustom.setSelected(true);
      String caps[] = vpn.caps.split(",");
      for(int a=0;a<caps.length;a++) {
        if (caps[a].equals("pap")) cap_pap.setSelected(true);
        if (caps[a].equals("chap")) cap_chap.setSelected(true);
        if (caps[a].equals("mschap")) cap_mschap.setSelected(true);
        if (caps[a].equals("mschapv2")) cap_mschapv2.setSelected(true);
        if (caps[a].equals("eap")) cap_eap.setSelected(true);
      }
      String capsOpts[] = vpn.capsOpts.split(",");
      for(int a=0;a<capsOpts.length;a++) {
        if (capsOpts[a].equals("mppe-all")) {capOpt_mppe_type.setSelectedIndex(0); capOpt_mppe.setSelected(true);}
        if (capsOpts[a].equals("mppe-128")) {capOpt_mppe_type.setSelectedIndex(1); capOpt_mppe.setSelected(true);}
        if (capsOpts[a].equals("mppe-40")) {capOpt_mppe_type.setSelectedIndex(2); capOpt_mppe.setSelected(true);}
        if (capsOpts[a].equals("mppe-stateful")) capOpt_mppe_stateful.setSelected(true);
        if (capsOpts[a].equals("bsd")) capOpt_bsd.setSelected(true);
        if (capsOpts[a].equals("tcp")) capOpt_tcp.setSelected(true);
        if (capsOpts[a].equals("echo")) capOpt_echo.setSelected(true);
      }
    }
    DefaultTableModel model = (DefaultTableModel)routesTable.getModel();
    String routes[] = vpn.routes.split(";");
    for(int a=0;a<routes.length;a++) {
      String f[] = routes[a].split(",");
      if (f.length != 4) continue;
      model.addRow(new Object[] {f[0], f[1], f[2], f[3]});
    }
    String routesOpts[] = vpn.routeOpts.split(",");
    for(int a=0;a<routesOpts.length;a++) {
      if (routesOpts[a].startsWith("network=")) {
        routeNetwork.setSelected(true);
        routeNetworkMask.setText(routesOpts[a].substring(8));
      }
    }
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    buttonGroup1 = new javax.swing.ButtonGroup();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    capsWindows = new javax.swing.JRadioButton();
    capsCustom = new javax.swing.JRadioButton();
    name = new javax.swing.JTextField();
    jTabbedPane1 = new javax.swing.JTabbedPane();
    userDetails = new javax.swing.JPanel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    username = new javax.swing.JTextField();
    password = new javax.swing.JPasswordField();
    jLabel5 = new javax.swing.JLabel();
    domain = new javax.swing.JTextField();
    routesScroll = new javax.swing.JScrollPane();
    routesPanel = new javax.swing.JPanel();
    routeNetwork = new javax.swing.JCheckBox();
    jScrollPane3 = new javax.swing.JScrollPane();
    routesTable = new javax.swing.JTable();
    addRoute = new javax.swing.JButton();
    deleteRoute = new javax.swing.JButton();
    jLabel10 = new javax.swing.JLabel();
    routeNetworkMask = new javax.swing.JTextField();
    customScroll = new javax.swing.JScrollPane();
    customPanel = new javax.swing.JPanel();
    cap_pap = new javax.swing.JCheckBox();
    cap_chap = new javax.swing.JCheckBox();
    cap_eap = new javax.swing.JCheckBox();
    cap_mschap = new javax.swing.JCheckBox();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    capOpt_mppe = new javax.swing.JCheckBox();
    capOpt_mppe_stateful = new javax.swing.JCheckBox();
    capOpt_bsd = new javax.swing.JCheckBox();
    capOpt_deflate = new javax.swing.JCheckBox();
    capOpt_tcp = new javax.swing.JCheckBox();
    capOpt_echo = new javax.swing.JCheckBox();
    cap_mschapv2 = new javax.swing.JCheckBox();
    jLabel9 = new javax.swing.JLabel();
    capOpt_mppe_type = new javax.swing.JComboBox();
    jLabel6 = new javax.swing.JLabel();
    host = new javax.swing.JTextField();
    accept = new javax.swing.JButton();
    cancel = new javax.swing.JButton();
    jLabel11 = new javax.swing.JLabel();
    domainsearch = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("VPN Details");

    jLabel1.setText("Name");

    jLabel2.setText("Type");

    buttonGroup1.add(capsWindows);
    capsWindows.setSelected(true);
    capsWindows.setText("Windows Compatible");

    buttonGroup1.add(capsCustom);
    capsCustom.setText("Custom");

    jLabel3.setText("Username");

    jLabel4.setText("Password");

    jLabel5.setText("Domain");
    jLabel5.setToolTipText("(optional)");

    javax.swing.GroupLayout userDetailsLayout = new javax.swing.GroupLayout(userDetails);
    userDetails.setLayout(userDetailsLayout);
    userDetailsLayout.setHorizontalGroup(
      userDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(userDetailsLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(userDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jLabel3)
          .addComponent(jLabel4)
          .addComponent(jLabel5))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(userDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(password)
          .addComponent(username)
          .addComponent(domain, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE))
        .addContainerGap())
    );
    userDetailsLayout.setVerticalGroup(
      userDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(userDetailsLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(userDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel3)
          .addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(userDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel4)
          .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(userDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel5)
          .addComponent(domain, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(277, Short.MAX_VALUE))
    );

    jTabbedPane1.addTab("User Details", userDetails);

    routeNetwork.setSelected(true);
    routeNetwork.setText("Add route to remote network");
    routeNetwork.setToolTipText("");

    routesTable.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {

      },
      new String [] {
        "Address", "Netmask", "Gateway", "Metric"
      }
    ) {
      Class[] types = new Class [] {
        java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
      };

      public Class getColumnClass(int columnIndex) {
        return types [columnIndex];
      }
    });
    jScrollPane3.setViewportView(routesTable);

    addRoute.setText("Add");
    addRoute.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        addRouteActionPerformed(evt);
      }
    });

    deleteRoute.setText("Delete");
    deleteRoute.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        deleteRouteActionPerformed(evt);
      }
    });

    jLabel10.setText("remote subnet mask");

    routeNetworkMask.setText("255.255.255.0");

    javax.swing.GroupLayout routesPanelLayout = new javax.swing.GroupLayout(routesPanel);
    routesPanel.setLayout(routesPanelLayout);
    routesPanelLayout.setHorizontalGroup(
      routesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(routesPanelLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(routesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
          .addGroup(routesPanelLayout.createSequentialGroup()
            .addComponent(addRoute)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(deleteRoute))
          .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGroup(routesPanelLayout.createSequentialGroup()
            .addGap(21, 21, 21)
            .addComponent(jLabel10)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(routeNetworkMask))
          .addComponent(routeNetwork))
        .addContainerGap(138, Short.MAX_VALUE))
    );
    routesPanelLayout.setVerticalGroup(
      routesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(routesPanelLayout.createSequentialGroup()
        .addContainerGap()
        .addComponent(routeNetwork)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(routesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel10)
          .addComponent(routeNetworkMask, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGap(8, 8, 8)
        .addGroup(routesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(addRoute)
          .addComponent(deleteRoute))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(161, Short.MAX_VALUE))
    );

    routesScroll.setViewportView(routesPanel);

    jTabbedPane1.addTab("Routing", routesScroll);

    cap_pap.setText("PAP");

    cap_chap.setText("CHAP");

    cap_eap.setText("EAP");

    cap_mschap.setText("MSCHAP");

    jLabel7.setText("Options");

    jLabel8.setText("Authentication");

    capOpt_mppe.setText("Enable P2P Encryption (MPPE)");

    capOpt_mppe_stateful.setText("Enable stateful encryption");

    capOpt_bsd.setText("Enable BSD data compression");

    capOpt_deflate.setText("Enable Deflate data compression");

    capOpt_tcp.setText("Enable TCP header compression");

    capOpt_echo.setText("Enable PPP echo packets");

    cap_mschapv2.setText("MSCHAPv2");

    jLabel9.setText("Type");

    capOpt_mppe_type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All available (Default)", "128bit", "40bit" }));

    javax.swing.GroupLayout customPanelLayout = new javax.swing.GroupLayout(customPanel);
    customPanel.setLayout(customPanelLayout);
    customPanelLayout.setHorizontalGroup(
      customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(customPanelLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(cap_mschapv2)
          .addComponent(capOpt_echo)
          .addComponent(capOpt_tcp)
          .addComponent(capOpt_deflate)
          .addComponent(capOpt_bsd)
          .addComponent(capOpt_mppe)
          .addComponent(cap_eap)
          .addComponent(jLabel7)
          .addComponent(cap_mschap)
          .addComponent(jLabel8)
          .addComponent(cap_pap)
          .addComponent(cap_chap)
          .addGroup(customPanelLayout.createSequentialGroup()
            .addGap(21, 21, 21)
            .addGroup(customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
              .addGroup(customPanelLayout.createSequentialGroup()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(capOpt_mppe_type, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              .addComponent(capOpt_mppe_stateful))))
        .addContainerGap(216, Short.MAX_VALUE))
    );
    customPanelLayout.setVerticalGroup(
      customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(customPanelLayout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel8)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(cap_pap)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(cap_chap)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(cap_mschap)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(cap_mschapv2)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(cap_eap)
        .addGap(19, 19, 19)
        .addComponent(jLabel7)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(capOpt_mppe)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel9)
          .addComponent(capOpt_mppe_type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(capOpt_mppe_stateful)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(capOpt_bsd)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(capOpt_deflate)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(capOpt_tcp)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(capOpt_echo)
        .addContainerGap(34, Short.MAX_VALUE))
    );

    customScroll.setViewportView(customPanel);

    jTabbedPane1.addTab("Custom Details", customScroll);

    jLabel6.setText("Host");

    accept.setText("Accept");
    accept.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        acceptActionPerformed(evt);
      }
    });

    cancel.setText("Cancel");
    cancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cancelActionPerformed(evt);
      }
    });

    jLabel11.setText("Domain Suffix");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jTabbedPane1)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(name))
          .addGroup(layout.createSequentialGroup()
            .addComponent(jLabel6)
            .addGap(19, 19, 19)
            .addComponent(host))
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addGap(0, 0, Short.MAX_VALUE)
            .addComponent(cancel)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(accept))
          .addGroup(layout.createSequentialGroup()
            .addComponent(jLabel2)
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(capsCustom)
              .addComponent(capsWindows))
            .addGap(0, 0, Short.MAX_VALUE))
          .addGroup(layout.createSequentialGroup()
            .addComponent(jLabel11)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(domainsearch)))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel1)
          .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel6)
          .addComponent(host, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel2)
          .addComponent(capsWindows))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(capsCustom)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel11)
          .addComponent(domainsearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(accept)
          .addComponent(cancel))
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
    dispose();
  }//GEN-LAST:event_cancelActionPerformed

  private void acceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptActionPerformed
    if (name.getText().length() == 0) return;
    if (host.getText().length() == 0) return;
    accepted = true;
    dispose();
  }//GEN-LAST:event_acceptActionPerformed

  private void addRouteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRouteActionPerformed
    DefaultTableModel model = (DefaultTableModel)routesTable.getModel();
    model.addRow(new Object[] {"","","",""});
    routesTable.editCellAt(model.getRowCount()-1, 0);
  }//GEN-LAST:event_addRouteActionPerformed

  private void deleteRouteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteRouteActionPerformed
    DefaultTableModel model = (DefaultTableModel)routesTable.getModel();
    int idx = routesTable.getSelectedRow();
    if (idx == -1) return;
    model.removeRow(idx);
  }//GEN-LAST:event_deleteRouteActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton accept;
  private javax.swing.JButton addRoute;
  private javax.swing.ButtonGroup buttonGroup1;
  private javax.swing.JButton cancel;
  private javax.swing.JCheckBox capOpt_bsd;
  private javax.swing.JCheckBox capOpt_deflate;
  private javax.swing.JCheckBox capOpt_echo;
  private javax.swing.JCheckBox capOpt_mppe;
  private javax.swing.JCheckBox capOpt_mppe_stateful;
  private javax.swing.JComboBox capOpt_mppe_type;
  private javax.swing.JCheckBox capOpt_tcp;
  private javax.swing.JCheckBox cap_chap;
  private javax.swing.JCheckBox cap_eap;
  private javax.swing.JCheckBox cap_mschap;
  private javax.swing.JCheckBox cap_mschapv2;
  private javax.swing.JCheckBox cap_pap;
  private javax.swing.JRadioButton capsCustom;
  private javax.swing.JRadioButton capsWindows;
  private javax.swing.JPanel customPanel;
  private javax.swing.JScrollPane customScroll;
  private javax.swing.JButton deleteRoute;
  private javax.swing.JTextField domain;
  private javax.swing.JTextField domainsearch;
  private javax.swing.JTextField host;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JScrollPane jScrollPane3;
  private javax.swing.JTabbedPane jTabbedPane1;
  private javax.swing.JTextField name;
  private javax.swing.JPasswordField password;
  private javax.swing.JCheckBox routeNetwork;
  private javax.swing.JTextField routeNetworkMask;
  private javax.swing.JPanel routesPanel;
  private javax.swing.JScrollPane routesScroll;
  private javax.swing.JTable routesTable;
  private javax.swing.JPanel userDetails;
  private javax.swing.JTextField username;
  // End of variables declaration//GEN-END:variables

  public boolean accepted = false;

  public void get(VPNPanel.VPN vpn) {
    vpn.name = name.getText();
    vpn.host = host.getText();
    if (capsWindows.isSelected()) {
      vpn.caps = "windows";
      vpn.capsOpts = "windows";
    } else {
      String caps = "";
      if (cap_pap.isSelected()) caps += ",pap";
      if (cap_chap.isSelected()) caps += ",chap";
      if (cap_mschap.isSelected()) caps += ",mschap";
      if (cap_mschapv2.isSelected()) caps += ",mschapv2";
      if (cap_eap.isSelected()) caps += ",eap";
      if (caps.startsWith(",")) caps = caps.substring(1);
      vpn.caps = caps;
      String capsOpts = "";
      if (capOpt_mppe.isSelected()) {
        switch (capOpt_mppe_type.getSelectedIndex()) {
          case 0: capsOpts += ",mppe-all"; break;
          case 1: capsOpts += ",mppe-128"; break;
          case 2: capsOpts += ",mppe-40"; break;
        }
      }
      if (capOpt_mppe_stateful.isSelected()) capsOpts += ",mppe-stateful";
      if (capOpt_bsd.isSelected()) capsOpts += ",bsd";
      if (capOpt_tcp.isSelected()) capsOpts += ",tcp";
      if (capOpt_echo.isSelected()) capsOpts += ",echo";
      vpn.capsOpts = capsOpts;
    }
    DefaultTableModel model = (DefaultTableModel)routesTable.getModel();
    int cnt = model.getRowCount();
    String routes = "";
    for(int a=0;a<cnt;a++) {
      String route = (String)model.getValueAt(a, 0) + ","
        + (String)model.getValueAt(a, 1) + ","
        + (String)model.getValueAt(a, 2) + ","
        + (String)model.getValueAt(a, 3);
      if (a > 0) routes += ";";
      routes += route;
    }
    vpn.routes = routes;
    String routesOpts = "";
    if (routeNetwork.isSelected()) routesOpts += ",network=" + routeNetworkMask.getText();
    vpn.user = username.getText();
    vpn.pass = new String(password.getPassword());
    vpn.domain = domain.getText();
    vpn.domainsearch = domainsearch.getText();
    vpn.routeOpts = routesOpts;
  }
  private void setPosition() {
    Rectangle s = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    Dimension d = getSize();
    setLocation(s.width/2 - d.width/2, s.height/2 - (d.height/2));
  }
}
